<?php
//救助人管理

namespace App\Http\Controllers\Manage;

use App\Http\Controllers\BaseController;
use App\Services\Manage\AssistantManageService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class AssistantController extends BaseController
{

    private AssistantManageService $assistantManageService;

    public function __construct(AssistantManageService $assistantManageService)
    {
        $this->assistantManageService = $assistantManageService;
    }

    /**
     * 协助人列表
     * @param  Request  $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function list(Request $request)
    {
        $page = $request->get('page', 1);
        $pageSize = $request->get('page_size', 20);
        $data = $request->all();

        $res = $this->assistantManageService::list($data, $page, $pageSize);

        return $this->success($res);
    }

    /**
     * 领券人导入校验
     * @param  Request  $request
     * @return JsonResponse
     */
    public function importAssistantVerify(Request $request)
    {
        $file = $request->file('file');
        $activityId = $request->post('activity_id');

        $res = $this->assistantManageService::importAssistantVerify($activityId, $file);

        if ($res['errcode']) {
            return $this->error($res['errcode'], $res['errmsg']);
        }

        return $this->success($res['data']);
    }

    /**
     * 领券人导入
     * @param  Request  $request
     * @return JsonResponse
     */
    public function importAssistant(Request $request)
    {
        $file = $request->file('file');
        $activityId = $request->post('activity_id');

        $res = $this->assistantManageService::importAssistantFile($activityId, $file);

        if ($res['errcode']) {
            return $this->error($res['errcode'], $res['errmsg']);
        }

        return $this->success([], '导入成功');
    }


    /**
     * 受助人导入模版url
     * @param  Request  $request
     * @return JsonResponse
     */
    public function importTemplateUrl(Request $request)
    {
        $url = 'https://outsource-public-read.tos-cn-beijing.volces.com/csaf-elderlymeal/uploads/template/协助者导入模版.xlsx';

        return $this->success(['url' => $url]);
    }


}